package com.campus.secondhand.model.vo;

import com.campus.secondhand.entity.Order;
import com.campus.secondhand.entity.OrderReview;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Data
public class OrderVO {
    private Long id;
    private String orderNo;
    private Long buyerId;
    private Long sellerId;
    private Long productId;
    private BigDecimal price;
    private Integer status;
    private Boolean isReviewed;
    private String transactionLocation; // 交易地点
    private String paymentMethod; // 支付方式
    private String remark; // 备注
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;

    // 额外信息
    private String productName; // 商品名称
    private String productImageUrl; // 商品图片
    private String sellerName; // 卖家名称
    private String sellerAvatar; // 卖家头像
    private String buyerName; // 买家名称
    private String buyerAvatar; // 买家头像

    // 买方评价信息
    private OrderReviewVO buyerReview;

    // 卖方评价信息
    private OrderReviewVO sellerReview;

    // 从Order实体转换为VO的方法
    public static OrderVO fromOrder(Order order) {
        OrderVO vo = new OrderVO();
        vo.setId(order.getId());
        vo.setOrderNo(order.getOrderNo());
        vo.setBuyerId(order.getBuyerId());
        vo.setSellerId(order.getSellerId());
        vo.setProductId(order.getProductId());
        vo.setPrice(order.getPrice());
        vo.setStatus(order.getStatus());
        vo.setIsReviewed(order.getIsReviewed());
        vo.setTransactionLocation(order.getTransactionLocation());
        vo.setPaymentMethod(order.getPaymentMethod());
        vo.setRemark(order.getRemark());
        vo.setCreatedAt(order.getCreatedAt());
        vo.setUpdatedAt(order.getUpdatedAt());
        return vo;
    }

    // 评价VO内部类
    @Data
    public static class OrderReviewVO {
        private Long id;
        private String content;
        private Integer ratingScore;
        private Integer creditScore;
        private LocalDateTime createdAt;

        // 从OrderReview实体转换为VO的方法
        public static OrderReviewVO fromOrderReview(OrderReview review) {
            if (review == null) {
                return null;
            }

            OrderReviewVO vo = new OrderReviewVO();
            vo.setId(review.getId());
            vo.setContent(review.getContent());
            vo.setRatingScore(review.getRatingScore());
            vo.setCreditScore(review.getCreditScore());
            vo.setCreatedAt(review.getCreatedAt());
            return vo;
        }
    }
}